﻿var expenseType = ref.ExpenseType.getValue();

//当修改ExpenseType的值的时候清空BudgetItems
ref.BudgetItems.reset();
ref.BudgetItems.getStore().removeAll();

var vm = this.lookupViewModel();
if (expenseType == "3") {
    ref.radio1.show();
    ref.carLine.show();
    ref.radio1.setAllowBlank(false);
} else {
    ref.radio1.hide();
    ref.carLine.hide();
    ref.radio1.setAllowBlank(true);
}
var status = vm.get('NebulogyForm.companySection.status');
if (status == 'launch' || status == 'resubmit') {
    Ext.PAIRest.request({
        ns: PAI.application.url,
        url: 'last/dictItemObj/customQuery',
        method: "POST",
        async: false,
        data: {
            "fields": [{
                "name": "id"
            }, {
                "exp": "$." + PAI.Global.getLanguage(),
                "name": "name",
                "type": "json"
            }, {
                "name": "code"
            }, {
                "name": "orderIndex"
            }],
            filter: "t1.pId='f4fabe6a-6362-4fdb-a54f-359e5e5b77ec'"
        },
        success: function (result) {
            var selectText = ref.ExpenseType.getRawValue();

            var data = result.data.filter(function (record) {
                return record.name == selectText;
            });

            vm.set('NebulogyForm.othersSection.others.PurchasingEmp', data[0].code.replace(selectText + '#', ''));
        }
    });
}
if (status == 'launch' || status == 'resubmit') {
    vm.set('NebulogyForm.launchEmployeeNo', PAI.Global.getAccount().employee.employeeNo);
}

var employeeNo = vm.get('NebulogyForm.launchEmployeeNo');


//根据登录用户编码和费用类型拉去 BudgetItems 数据
Ext.PAIRest.request({
    ns: PAI.application.serviceUrl + '/budget-rest/',
    url: 'api/budgetRelationItem/getBudgetItemByEmployeeNo',
    method: "POST",
    data: {
        employeeNo: employeeNo,
        expenseType: ref.ExpenseType.getRawValue()
    },
    success: function (result) {

        var store = ref.BudgetItems.getStore();
        store.removeAll();
        Ext.each(result.data, function (record) {
            record.label = record.budgetitemDescription;
            record.value = record.id;
        });
        store.loadData(result.data);
    }
});
